//
//  ForgetPasswordViewController.m
//  阿帕
//
//  Created by mac on 2020/1/8.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "ForgetPasswordViewController.h"
#import "ImageUploadViewController.h"
#import "ImageVerifyAlert.h"

@interface ForgetPasswordViewController ()<DeliveredImageUrlDelegate>
{
    UIView *_noChangePhoneNumView;
    UIView *_changePhoneNumView;
    
    NSString *_judge;//是否更换手机号 0不更换 1更换
    NSString *_idImg;//身份证照
    NSString *_idBackImg;//身份证背面照
    NSString *_idInhandImg;//手持身份证照
    NSString *_licenseImg;//营业执照照片
}
@property (strong , nonatomic)UIButton *confirmButton;

@end

@implementation ForgetPasswordViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationItem.title = @"找回密码";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self viewsLayout];
 
    _judge = @"0";
    _idImg = @"";
    _idBackImg = @"";
    _idInhandImg = @"";
    _licenseImg = @"";

}

- (void)viewsLayout{
    
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 120, 45)];
    textLabel.text = @"是否更换手机号";
    textLabel.textColor = Dark_TextColor;
    textLabel.font = font(14);
    textLabel.adjustsFontSizeToFitWidth = YES;
    [self.view addSubview:textLabel];
    
    UIButton *changePhoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    changePhoneBtn.tag = 10;
    [changePhoneBtn setTitle:@"是否更换手机号" forState:UIControlStateNormal];
    changePhoneBtn.titleLabel.font = font(14);
    changePhoneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [changePhoneBtn setImage:image(@"gcy_img_home_business_nomal") forState:UIControlStateNormal];
    [changePhoneBtn addTarget:self action:@selector(btnTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [changePhoneBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    changePhoneBtn.frame = CGRectMake(ScreenW-215, 0, 200, 45);
    changePhoneBtn.repeatEventInterval = 0.3f;
    [self.view addSubview:changePhoneBtn];
    [changePhoneBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    
#pragma mark - 不更换手机号视图
    _noChangePhoneNumView = [[UIView alloc] initWithFrame:CGRectMake(0, 45, ScreenW, 180)];
    _noChangePhoneNumView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_noChangePhoneNumView];
    
    NSArray *noIconArr = @[@"gcy_img_register_tel",@"gcy_img_forPsd_code",@"gcy_img_register_psd",@"gcy_img_register_cpsd"];
    NSArray *noPlaceholderArr = @[@"请填写原手机号",@"请填写验证码",@"请填写新密码",@"请确认新密码"];
    
    for (int i=0; i<noIconArr.count; i++) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 45*i, ScreenW, 45)];
        [_noChangePhoneNumView addSubview:bgView];
        
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5f, 20, 20)];
        icon.contentMode = UIViewContentModeScaleAspectFit;
        icon.image = image(noIconArr[i]);
        [bgView addSubview:icon];
        
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(icon.cy_right + 10, 0, 230, 45)];
        textField.tag = 20 + i;
        textField.font = font(14);
        textField.text = @"";
        textField.textColor = Dark_TextColor;
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:noPlaceholderArr[i] attributes:@{NSForegroundColorAttributeName: Light_TextColor}];
        [bgView addSubview:textField];
        if (i<2) {
            textField.keyboardType = UIKeyboardTypeNumberPad;
            if (i==0) {
                textField.textFieldType = CJTextFieldStringTypeNumber;
                textField.maxLength = 11;
            } else if (i==1) {
                textField.textFieldType = CJTextFieldStringTypeNumber;
                textField.maxLength = 6;
            }
        } else {
            
            if (i==2) {
//                textField.textFieldType = CJTextFieldStringTypePassword;
                textField.maxLength = 18;
            } else if (i==3) {
//                textField.textFieldType = CJTextFieldStringTypePassword;
                textField.maxLength = 18;
            }
            textField.secureTextEntry = YES;
        }
        
        //分割线
        UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(10, 0, ScreenW - 20, 1)];
        hLine.backgroundColor = BackgroundColor;
        [bgView addSubview:hLine];
        
        if (i==0) {
            UIButton *codeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            codeBtn.tag = 30;
            cut(codeBtn, BTN_BORDER_RADIUS);
            [codeBtn setTitle:@"验证码" forState:UIControlStateNormal];
            codeBtn.titleLabel.font = font(14);
            codeBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
            [codeBtn setBackgroundColor:Theme_ColorValue];
            [codeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            codeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [codeBtn addTarget:self action:@selector(btnTypeClick:) forControlEvents:UIControlEventTouchUpInside];
            codeBtn.frame = CGRectMake(ScreenW-95, 5, 80, 35);
            [bgView addSubview:codeBtn];
        }
        
        //设置隐藏显示密码
        if (i == 2) {
            UIButton *hsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [hsBtn addTarget:self action:@selector(showOrHiddenPsdEvent:) forControlEvents:UIControlEventTouchUpInside];
            hsBtn.frame = CGRectMake(ScreenW-35, 17.5f, 18, 10);
            [hsBtn setImage:image(@"gcy_icon_close_eye") forState:UIControlStateNormal];
            [bgView addSubview:hsBtn];
        }
    }
    
#pragma mark - 换手机号视图
    _changePhoneNumView = [[UIView alloc] initWithFrame:CGRectMake(0, 45, ScreenW, 8*45)];
    _changePhoneNumView.backgroundColor = [UIColor whiteColor];
    _changePhoneNumView.hidden = YES;
    [self.view addSubview:_changePhoneNumView];
    
    NSArray *iconArr = @[@"gcy_img_register_tel",@"gcy_img_forPsd_nTel",@"gcy_img_forPsd_code",@"gcy_img_register_psd",@"gcy_img_register_cpsd"];
    NSArray *placeholderArr = @[@"请填写原手机号",@"请填写新手机号",@"请填写验证码",@"请填写新密码",@"请确认新密码",@"*司机身份证人像面照片未上传",@"*司机身份证国徽面照片未上传",@"*手持身份证照未上传"];
    
    self.confirmButton.frame = CGRectMake(20, _noChangePhoneNumView.cy_bottom + 10, ScreenW-40, 45);
    
    for (int i=0; i<placeholderArr.count; i++) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 45*i, ScreenW, 45)];
        [_changePhoneNumView addSubview:bgView];
        
        if (i<5) {
            UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5f, 20, 20)];
            icon.contentMode = UIViewContentModeScaleAspectFit;
            icon.image = image(iconArr[i]);
            [bgView addSubview:icon];
            
            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(icon.cy_right + 10, 0, 230, 45)];
            textField.tag = 200 + i;
            textField.font = font(14);
            textField.text = @"";
            textField.textColor = Dark_TextColor;
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderArr[i] attributes:@{NSForegroundColorAttributeName: Light_TextColor}];
            [bgView addSubview:textField];
            if (i<3) {
                textField.keyboardType = UIKeyboardTypeNumberPad;
                if (i==0) {
                    textField.textFieldType = CJTextFieldStringTypeNumber;
                    textField.maxLength = 11;
                } else if (i==1) {
                    textField.textFieldType = CJTextFieldStringTypeNumber;
                    textField.maxLength = 11;
                } else if (i==2) {
                    textField.textFieldType = CJTextFieldStringTypeNumber;
                    textField.maxLength = 6;
                }
            } else {
                textField.secureTextEntry = YES;
                if (i==3) {
//                    textField.textFieldType = CJTextFieldStringTypePassword;
                    textField.maxLength = 18;
                } else if (i==4) {
//                    textField.textFieldType = CJTextFieldStringTypePassword;
                    textField.maxLength = 18;
                }
            }
        }
        
        //分割线
        UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(10, 0, ScreenW - 20, 1)];
        hLine.backgroundColor = BackgroundColor;
        [bgView addSubview:hLine];
        
        if (i==1) {
            UIButton *codeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            codeBtn.tag = 300;
            cut(codeBtn, BTN_BORDER_RADIUS);
            [codeBtn setTitle:@"验证码" forState:UIControlStateNormal];
            codeBtn.titleLabel.font = font(14);
            codeBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
            [codeBtn setBackgroundColor:Theme_ColorValue];
            [codeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            codeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [codeBtn addTarget:self action:@selector(btnTypeClick:) forControlEvents:UIControlEventTouchUpInside];
            codeBtn.frame = CGRectMake(ScreenW-95, 5, 80, 35);
            [bgView addSubview:codeBtn];
        }
        
        if (i>=5) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(15, 0, ScreenW-50, 45);
            button.tag = 300 + i;
            [button setTitle:placeholderArr[i] forState:UIControlStateNormal];
            button.titleLabel.font = font(14);
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(btnTypeClick:) forControlEvents:UIControlEventTouchUpInside];
            [bgView addSubview:button];

            UIImageView *arrow = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenW-30, 17, 6, 11)];
            arrow.image = image(@"gcy_icon_hd_rarrow");
            [bgView addSubview:arrow];
        }

    }
}

#pragma mark - 隐藏显示密码
- (IBAction)showOrHiddenPsdEvent:(UIButton *)sender {
    
    UITextField *psdTF = [self.view viewWithTag:22];
    UITextField *conPsdTF = [self.view viewWithTag:23];
    
    if (sender.selected) {
        [sender setImage:image(@"gcy_icon_close_eye") forState:UIControlStateNormal];
        psdTF.secureTextEntry = YES;
        conPsdTF.secureTextEntry = YES;
        
    } else {
        [sender setImage:image(@"gcy_icon_open_eye") forState:UIControlStateNormal];
        psdTF.secureTextEntry = NO;
        conPsdTF.secureTextEntry = NO;
        
    }
    sender.selected = !sender.selected;
}

- (void)btnTypeClick:(UIButton *)button {
    WEAKSELF
    if (button.tag == 10) {
        button.selected = !button.selected;
        if (button.selected) {
            //选中
            [button setImage:[image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue] forState:UIControlStateNormal];
            _noChangePhoneNumView.hidden = YES;
            _changePhoneNumView.hidden = NO;
            _judge = @"1";
            self.confirmButton.cy_y = _changePhoneNumView.cy_bottom + 10;
            
        } else{
            //未选中
            [button setImage:image(@"gcy_img_home_business_nomal") forState:UIControlStateNormal];
            _noChangePhoneNumView.hidden = NO;
            _changePhoneNumView.hidden = YES;
            _judge = @"0";
            self.confirmButton.cy_y = _noChangePhoneNumView.cy_bottom + 10;
        }
        
    } else if (button.tag == 30) {
        //不更换手机号 获取验证码
        
        //发送验证码
        UITextField *telTextField = [self.view viewWithTag:20];
        if (telTextField.text.length != 11) {
            [XSInfoView showInfo:@"请填写正确的手机号码" onView:self.view];
        } else {
            
            [self.view endEditing:YES];
            
            [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], PARTY_VALIDPHONE) withParameter:@{@"phone": telTextField.text} withVC:self netName:@"忘记密码手机号是否被注册" success:^(id response, NSString *msg) {
                
                [XSInfoView showInfo:msg onView:weakSelf.view];
                
            } failure:^(NSInteger code, NSString *msg) {
                
                if ([msg isEqual:@"手机号已被注册"]) {
                    
                    ImageVerifyAlert *imageVerifyAlert = [[ImageVerifyAlert alloc] initWithFrame:CGRectMake(0, 0, ScreenW-30, 210)];
                    imageVerifyAlert.backgroundColor = [UIColor whiteColor];
                    cut(imageVerifyAlert, 5);
                    imageVerifyAlert.phoneNum = telTextField.text;
                    [[GlobalPopUpTool sharedInstance] popUpWithView:imageVerifyAlert withViewController:self withAnimation:YES withCanTapBgCancel:YES];
                    imageVerifyAlert.sendImgCodeBlock = ^(BOOL isConfirm, NSString * _Nonnull code) {
                        if (isConfirm) {
                            
                            NSDictionary *params = @{@"partyGroupCode": [UserDefaultUtil valueForKey:BranchCode],
                                                     @"phone":telTextField.text,
                                                     @"imageCode": code,
                                                     @"time": [DCSpeedy getCurrentTimes],
                            };
                            
                            [HTTPManager postNetworkRequest:[NSString stringWithFormat:@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], SMS_SENDVERIFICATIONCODE] withParameter:params withVC:self netName:@"获取验证码" success:^(id response, NSString *msg) {
                                
                                [[GlobalPopUpTool sharedInstance] removePopUpView];
                                
                                [XSInfoView showInfo:msg onView:weakSelf.view];
                                //开始倒计时
                                [self theCountdown];
                                
                            } failure:^(NSInteger code, NSString *msg) {
                                
                                [[GlobalPopUpTool sharedInstance] removePopUpView];
                            }];
                            
                        } else {
                            [[GlobalPopUpTool sharedInstance] removePopUpView];
                        }
                    };
                }
            }];
            
        }
        
    } else if (button.tag == 300) {
        //更换手机号 获取验证码
        
        UITextField *newTelTextField = [self.view viewWithTag:201];
        if (newTelTextField.text.length != 11) {
            [XSInfoView showInfo:@"请填写正确的手机号码~" onView:self.view];
        } else {
            
            [self.view endEditing:YES];
            
            [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], PARTY_VALIDPHONE) withParameter:@{@"phone": newTelTextField.text} withVC:self netName:@"注册手机号是否被注册" success:^(id response, NSString *msg) {
            
                ImageVerifyAlert *imageVerifyAlert = [[ImageVerifyAlert alloc] initWithFrame:CGRectMake(0, 0, ScreenW-30, 210)];
                imageVerifyAlert.backgroundColor = [UIColor whiteColor];
                cut(imageVerifyAlert, 5);
                imageVerifyAlert.phoneNum = newTelTextField.text;
                [[GlobalPopUpTool sharedInstance] popUpWithView:imageVerifyAlert withViewController:self withAnimation:YES withCanTapBgCancel:YES];
                imageVerifyAlert.sendImgCodeBlock = ^(BOOL isConfirm, NSString * _Nonnull code) {
                    if (isConfirm) {
                        
                        NSDictionary *params = @{@"partyGroupCode": [UserDefaultUtil valueForKey:BranchCode],
                                                 @"phone":newTelTextField.text,
                                                 @"imageCode": code,
                                                 @"time": [DCSpeedy getCurrentTimes],
                        };
                        
                        [HTTPManager postNetworkRequest:[NSString stringWithFormat:@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], SMS_SENDVERIFICATIONCODE] withParameter:params withVC:self netName:@"获取验证码" success:^(id response, NSString *msg) {
                            
                            [[GlobalPopUpTool sharedInstance] removePopUpView];
                            
                            [XSInfoView showInfo:msg onView:weakSelf.view];
                            //开始倒计时
                            [self theCountdownTwo];
                            
                        } failure:^(NSInteger code, NSString *msg) {
                           
                            [[GlobalPopUpTool sharedInstance] removePopUpView];
                        }];
                        
                    } else {
                        [[GlobalPopUpTool sharedInstance] removePopUpView];
                    }
                };
                
            } failure:^(NSInteger code, NSString *msg) {
                
            }];
                    
        }
        
    } else {
        
        ImageUploadViewController *iuvc = [[ImageUploadViewController alloc] init];
        iuvc.delegate = self;
        iuvc.fpwEncryString = [[NSString stringWithFormat:@"%@%@", [DCSpeedy currentTimeYearMonthDayHours], [UserDefaultUtil valueForKey:Branch_Salt]] md5String];
        
        /**
         0 驾驶证
         1 从业资格证
         2 身份证正面
         3 身份证反面
         4 司机照
         5 行驶证
         6 道路运输证
         7 车头正面照
         8 挂车行驶证
         9 挂车运营证
         10 营业执照
         11 手持身份证
         */
        if (button.tag == 305) {
            //身份证正面照
            iuvc.imageType = 2;
            iuvc.imageNetUrl = _idImg;
            
        } else if (button.tag == 306) {
            //身份证反面照
            iuvc.imageType = 3;
            iuvc.imageNetUrl = _idBackImg;
            
        } else if (button.tag == 307) {
            //手持身份证照
            iuvc.imageType = 11;
            iuvc.imageNetUrl = _idInhandImg;
            
        } else if (button.tag == 308) {
            //营业执照
//            iuvc.imageType = 10;
//            iuvc.imageNetUrl = _licenseImg;
        }
        [self.navigationController pushViewController:iuvc animated:YES];
    }
}

#pragma mark -- DeliveredImageUrlDelegate
- (void)getImageUrlSting:(NSString *)string andImageType:(NSInteger)type {
    if (type == 2) {
        _idImg = string;
        UIButton *btn = [self.view viewWithTag:305];
        [btn setTitle:@"*司机身份证人像面照片已上传" forState:UIControlStateNormal];
        [btn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    } else if (type == 3) {
        _idBackImg = string;
        UIButton *btn = [self.view viewWithTag:306];
        [btn setTitle:@"*司机身份证国徽面照片已上传" forState:UIControlStateNormal];
        [btn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    } else if (type == 11) {
        _idInhandImg = string;
        UIButton *btn = [self.view viewWithTag:307];
        [btn setTitle:@"*手持身份证照已上传" forState:UIControlStateNormal];
        [btn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    } else if (type == 10) {
//        _licenseImg = string;
//        UIButton *btn = [self.view viewWithTag:308];
//        [btn setTitle:@"营业执照已上传" forState:UIControlStateNormal];
//        [btn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    }
}
#pragma mark -- 确认重置密码
- (void)confirmButtonClick {
    WEAKSELF
    if ([_judge isEqual:@"0"]) {
        //不更换
        UITextField *telTextField = [self.view viewWithTag:20];
        UITextField *codeTextField = [self.view viewWithTag:21];
        UITextField *newPsdTextField = [self.view viewWithTag:22];
        UITextField *conPsdTextField = [self.view viewWithTag:23];
        
        if (telTextField.text.length != 11) {
            [XSInfoView showInfo:@"手机号必须是11位" onView:self.view];
            return;
        }
        if (codeTextField.text.length != 6) {
            [XSInfoView showInfo:@"验证码必须是6位" onView:self.view];
            return;
        }
        if (newPsdTextField.text.length > 20 || conPsdTextField.text.length > 20) {
            [XSInfoView showInfo:@"密码最长为20位" onView:self.view];
            return;
        }
        
        if (![newPsdTextField.text isEqual:conPsdTextField.text]) {
            [XSInfoView showInfo:@"两次输入的密码不一致" onView:self.view];
            return;
        }
       
        
        if ([DCSpeedy isBlankString:telTextField.text] == YES || [DCSpeedy isBlankString:codeTextField.text] == YES || [DCSpeedy isBlankString:newPsdTextField.text] == YES || [DCSpeedy isBlankString:conPsdTextField.text] == YES) {
            [XSInfoView showInfo:@"信息填写不完整，请检查" onView:self.view];
            return;
        }
        NSDictionary *parmas = @{
            @"judge": _judge,
            @"phone": telTextField.text,
            @"verifyCode": codeTextField.text,
//            @"newPwd": newPsdTextField.text,
            @"newPwd": [DCSpeedy base64:newPsdTextField.text],
            @"userType": @"DRIVER",
        };
        [HTTPManager postNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], PARTY_FORGETPASS) withParameter:parmas withVC:self netName:@"忘记密码" success:^(id response, NSString *msg) {
            
            [XSInfoView showInfo:msg onView:weakSelf.view];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
        
    } else {
        //更换
        UITextField *telTextField = [self.view viewWithTag:200];
        UITextField *newTelTextField = [self.view viewWithTag:201];
        UITextField *codeTextField = [self.view viewWithTag:202];
        UITextField *newPsdTextField = [self.view viewWithTag:203];
        UITextField *conPsdTextField = [self.view viewWithTag:204];
        
        if (telTextField.text.length != 11 || newTelTextField.text.length != 11) {
            [XSInfoView showInfo:@"手机号必须是11位" onView:self.view];
            return;
        }
        if (codeTextField.text.length != 6) {
            [XSInfoView showInfo:@"验证码必须是6位" onView:self.view];
            return;
        }
        if (newPsdTextField.text.length > 20 || conPsdTextField.text.length > 20) {
            [XSInfoView showInfo:@"密码最长为20位" onView:self.view];
            return;
        }
        
        if ([DCSpeedy isBlankString:telTextField.text] == YES || [DCSpeedy isBlankString:codeTextField.text] == YES || [DCSpeedy isBlankString:newPsdTextField.text] == YES || [DCSpeedy isBlankString:conPsdTextField.text] == YES || [DCSpeedy isBlankString:newTelTextField.text] == YES || [DCSpeedy isBlankString:_idImg] == YES || [DCSpeedy isBlankString:_idBackImg] == YES || [DCSpeedy isBlankString:_idInhandImg] == YES) {
            [XSInfoView showInfo:@"信息填写不完整，请检查" onView:self.view];
            return;
        }
        NSDictionary *parmas = @{
            @"judge": _judge,
            @"phone": telTextField.text,
            @"newPhone": newTelTextField.text,
            @"verifyCode": codeTextField.text,
//            @"newPwd": newPsdTextField.text,
            @"newPwd": [DCSpeedy base64:newPsdTextField.text],
            @"idImg": _idImg,
            @"idBackImg": _idBackImg,
            @"idInhandImg": _idInhandImg,
            @"userType": @"DRIVER",
//            @"licenseImg": _licenseImg,
        };
        [HTTPManager postNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], PARTY_FORGETPASS) withParameter:parmas withVC:self netName:@"忘记密码" success:^(id response, NSString *msg) {
            
            [XSInfoView showInfo:msg onView:weakSelf.view];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
    }
}

- (void)theCountdown {
    
    UIButton *button = [self.view viewWithTag:30];
    
    __block int timeout= 59; //倒计时时间
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    
    dispatch_source_set_event_handler(_timer, ^{
        
        if(timeout<=0){ //倒计时结束，关闭
            
            dispatch_source_cancel(_timer);
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置界面的按钮显示 根据自己需求设置
                
                [button setTitle:@"验证码" forState:UIControlStateNormal];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [button setBackgroundColor:Theme_ColorValue];
                button.userInteractionEnabled = YES;
            });
            
        }else{
            
            //            int minutes = timeout / 60;
            
            int seconds = timeout % 60;
            
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置界面的按钮显示 根据自己需求设置
                
                [UIView beginAnimations:nil context:nil];
                
                [UIView setAnimationDuration:0];
                
                [button setTitle:[NSString stringWithFormat:@"%@ 秒",strTime] forState:UIControlStateNormal];
                //                [button setBackgroundColor:[UIColor whiteColor]];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                //                cutBorder(_sendCodeBtn, .5f, @"999999");
                //                [button setBackgroundColor:[UIColor clearColor]];
                [UIView commitAnimations];
                
                button.userInteractionEnabled = NO;
                
            });
            
            timeout--;
            
        }
        
    });
    
    dispatch_resume(_timer);
}

- (void)theCountdownTwo {
    
    UIButton *button = [self.view viewWithTag:300];
    
    __block int timeout= 59; //倒计时时间
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    
    dispatch_source_set_event_handler(_timer, ^{
        
        if(timeout<=0){ //倒计时结束，关闭
            
            dispatch_source_cancel(_timer);
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置界面的按钮显示 根据自己需求设置
                
                [button setTitle:@"验证码" forState:UIControlStateNormal];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [button setBackgroundColor:Theme_ColorValue];
                button.userInteractionEnabled = YES;
            });
            
        }else{
            
            //            int minutes = timeout / 60;
            
            int seconds = timeout % 60;
            
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置界面的按钮显示 根据自己需求设置
                
                [UIView beginAnimations:nil context:nil];
                
                [UIView setAnimationDuration:0];
                
                [button setTitle:[NSString stringWithFormat:@"%@ 秒",strTime] forState:UIControlStateNormal];
                //                [button setBackgroundColor:[UIColor whiteColor]];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                //                cutBorder(_sendCodeBtn, .5f, @"999999");
                //                [button setBackgroundColor:[UIColor clearColor]];
                [UIView commitAnimations];
                
                button.userInteractionEnabled = NO;
                
            });
            
            timeout--;
            
        }
        
    });
    
    dispatch_resume(_timer);
}
- (UIButton *)confirmButton {
    if (!_confirmButton) {
        _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmButton setTitle:@"重置密码" forState:UIControlStateNormal];
        [_confirmButton setBackgroundColor:Theme_ColorValue];
        cut(_confirmButton, BTN_BORDER_RADIUS);
        [_confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [_confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.view addSubview:_confirmButton];
    }
    return _confirmButton;
}

@end
